﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy4_10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 窗体加载事件：初始化候选名单
        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1
.Items.Add("小王");
            listBox1
.Items.Add("小李");
            listBox1
.Items.Add("小陈");
            listBox1
.Items.Add("小白");
            listBox1
.Items.Add("小刘");
            listBox1
.Items.Add("小徐");
        }

        // “添加”按钮点击事件：将输入的姓名加入候选名单
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                listBox1
.Items.Add(textBox1.Text);
                textBox1
.Text = "";
            }
        }

        // “删除”按钮点击事件：删除选中的候选名单
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                listBox1
.Items.RemoveAt(listBox1.SelectedIndex);
            }
        }

        // “去抽奖”按钮点击事件：打开Form2并传递候选名单
        private void btnDraw_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(listBox1); // 实例化Form2并传递ListBox
            this.Hide(); // 隐藏Form1
            f2
.ShowDialog(); // 显示Form2并等待其关闭
            this.Show(); // 重新显示Form1
        }
    }
}
